package com.mrt.chatgpt.data.trigger.job;

import com.google.common.eventbus.EventBus;
import com.mrt.chatgpt.data.domain.order.service.IOrderService;
import lombok.extern.slf4j.Slf4j;
import org.checkerframework.checker.units.qual.C;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.List;

/**
 * @Author 86135
 * @Date 2024/3/26 14:45
 * @Description
 * @Version 1.0
 * @快捷键 getterANDsetter ALT+Insert
 * @快捷键 Ctrl+/或者Ctrl+Shift+/都可以快速注释
 * @快捷键 Ctrl+D 快速复制代码
 * @“ctrl+r”快捷键,用于当前文件内容替换,指的是在当前打开的文件中替换匹配的字符,只操作一个文件;
 * @ALT+鼠标左键 整列编辑
 * @快捷键提示 ALT+Enter
 * @快捷键 快速写注释：在方法函数上方输入/** 然后回车
 * @快捷键 Ctrl+O，选择重写的方法
 * @快捷键 ALT+INSERT
 */
@Slf4j
@Component
public class OrderReplenishmentJob {

    @Resource
    private IOrderService orderService;
    @Resource
    private EventBus eventBus;

    /**
     * 执行订单补货，超时3分钟，已支付，待发货的订单
     */
    @Scheduled(cron ="0 0/10 * * * ?")
    public void exec(){
        try {
            List<String> orderIds = orderService.queryReplenishmentOrder();
            if(orderIds.isEmpty()){
                log.info("定时任务，订单补货不存在，查询 orderIds is null");
                return;
            }
            for(String orderId : orderIds){
                log.info("定时任务，订单补货开始。orderId: {}", orderId);
                eventBus.post(orderId);
            }
        }catch (Exception e) {
            log.error("定时任务，订单补货失败。", e);
        }
    }
}
